/**
 * ESC快捷键插件
 */
(function(E, $){

var Consts = E.consts,
	Event = E.mod('Event'),
	Selection = E.mod('Selection'),
	Panel = E.mod('Panel');

// 键盘按下事件，处理快捷键
Event.bind('keydown', function(dom, e){
	var self = this,
		keyCode = e.keyCode || e.which || e.charCode,
		text = ''+Selection.getText();
	
	if (e.ctrlKey || e.altKey || e.shiftKey || keyCode !== 27) {
		return;
	}
	
	if( text ){
		E.plugin("BaikeLink").click();
	}else{
		var target = Event.getTarget();
		if( /^(h\d|a|b|i|u|sup|sub|font)$/i.test(target.nodeName) ){
			$(target).replaceWith( target.innerHTML );
			E.monitor('esc');
		}else{
			Panel.hide();
		}
	}
	return false;
});


$(document).keydown(function(e){
	var keyCode = e.keyCode || e.which || e.charCode;
	if (!e.ctrlKey && !e.altKey && !e.shiftKey && keyCode === 27) {
		Panel.hide();
	}
});

})(jQEditor, jQuery);